package com.ruoyi.web.controller.order;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.web.controller.order.req.GetProductByPartNr;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.order.domain.MesOrderProduct;
import com.ruoyi.order.service.IMesOrderProductService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品列Controller
 * 
 * @author guoxl
 * @date 2025-04-03
 */
@RestController
@RequestMapping("/order/product")
public class MesOrderProductController extends BaseController
{
    @Autowired
    private IMesOrderProductService mesOrderProductService;

    /**
     * 查询产品列列表
     */
    @PreAuthorize("@ss.hasPermi('order:product:list')")
    @GetMapping("/list")
    public TableDataInfo list(MesOrderProduct mesOrderProduct)
    {
        startPage();
        List<MesOrderProduct> list = mesOrderProductService.selectMesOrderProductList(mesOrderProduct);
        return getDataTable(list);
    }

    /**
     * 导出产品列列表
     */
    @PreAuthorize("@ss.hasPermi('order:product:export')")
    @Log(title = "产品列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesOrderProduct mesOrderProduct)
    {
        List<MesOrderProduct> list = mesOrderProductService.selectMesOrderProductList(mesOrderProduct);
        ExcelUtil<MesOrderProduct> util = new ExcelUtil<MesOrderProduct>(MesOrderProduct.class);
        util.exportExcel(response, list, "产品列数据");
    }

    /**
     * 获取产品列详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:product:query')")
    @GetMapping(value = "/{productId}")
    public AjaxResult getInfo(@PathVariable("productId") Long productId)
    {
        return success(mesOrderProductService.selectMesOrderProductByProductId(productId));
    }
    /**
     * 获取产品列详细信息
     */
    @PostMapping(value = "/getByPartNr")
    public AjaxResult getInfo(@RequestBody GetProductByPartNr getProductByPartNr)
    {
        return success(mesOrderProductService.selectMesOrderProductByPartNr(getProductByPartNr.getPartNr()));
    }

    /**
     * 新增产品列
     */
    @PreAuthorize("@ss.hasPermi('order:product:add')")
    @Log(title = "产品列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesOrderProduct mesOrderProduct)
    {
        return toAjax(mesOrderProductService.insertMesOrderProduct(mesOrderProduct));
    }

    /**
     * 修改产品列
     */
    @PreAuthorize("@ss.hasPermi('order:product:edit')")
    @Log(title = "产品列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesOrderProduct mesOrderProduct)
    {
        return toAjax(mesOrderProductService.updateMesOrderProduct(mesOrderProduct));
    }

    /**
     * 删除产品列
     */
    @PreAuthorize("@ss.hasPermi('order:product:remove')")
    @Log(title = "产品列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productIds}")
    public AjaxResult remove(@PathVariable Long[] productIds)
    {
        return toAjax(mesOrderProductService.deleteMesOrderProductByProductIds(productIds));
    }
}
